//
//  EventReportTableViewController.m
//  Runone
//
//  Created by runone01 on 16/8/30.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "EventReportTableViewController.h"
#import "RightCodeTool.h"
#import "ConstructionEventReportViewController.h"
#import "ChargeReportedViewController.h"
#import "ChargeDataSubmitController.h"
#import "OtherEventsReportedViewController.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeigh   [UIScreen mainScreen].bounds.size.height
@interface EventReportTableViewController ()
@property(nonatomic,strong)NSMutableArray *dataSource;
@property(nonatomic, strong)NSMutableArray *vcDataArray;
@end

@implementation EventReportTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataSource = [[NSMutableArray alloc] init];
    _vcDataArray = [[NSMutableArray alloc] init];
    ConstructionEventReportViewController *ccVC=[[ConstructionEventReportViewController alloc] init];
    ChargeReportedViewController     *chargeVC=[[ChargeReportedViewController alloc] init];
    ChargeDataSubmitController       *dataSubmitVc = [[ChargeDataSubmitController alloc] init];
    OtherEventsReportedViewController *OtherVC=[[OtherEventsReportedViewController alloc] init];
    if ([[RightCodeTool sharedTool] rightIsEqualTO:@"P040403"]) {
        [_dataSource addObject:@"施工事件上报"];
        [_vcDataArray addObject:ccVC];
    }
    if ([[RightCodeTool sharedTool] rightIsEqualTO:@"P040404"]) {
        [_dataSource addObject:@"收费事件上报"];
        [_vcDataArray addObject:chargeVC];
    }
    if ([[RightCodeTool sharedTool] rightIsEqualTO:@"P040502"]) {
        [_dataSource addObject:@"收费数据上报"];
        [_vcDataArray addObject:dataSubmitVc];
    }
    if ([[RightCodeTool sharedTool] rightIsEqualTO:@"P040405"]) {
        [_dataSource addObject:@"其他事件上报"];
        [_vcDataArray addObject:OtherVC];
    }
    
    
     self.preferredContentSize=CGSizeMake(140, _dataSource.count * 44);
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CellID"];
 }

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID=@"CellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = self.dataSource[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.index!=nil) {
        self.index(indexPath.row);
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
